package com.ruoyi.warning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.warning.domain.entity.Sensor;
import com.ruoyi.warning.domain.query.SensorQuery;
import com.ruoyi.warning.mapper.SensorsMapper;
import com.ruoyi.warning.service.ISensorsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenhc
 * @since 2025-03-25
 */
@Service
public class SensorsServiceImpl extends ServiceImpl<SensorsMapper, Sensor> implements ISensorsService {

    @Override
    public Object getAllSensors(SensorQuery query) {
        LambdaQueryWrapper<Sensor> wrapper = new QueryWrapper<Sensor>().lambda()
                .eq(Sensor::getDeviceId, query.getDeviceId())
                .eq(query.getSensorClass()!= null,Sensor::getSensorClass,query.getSensorClass())
                .in(query.getSensorClassList()!= null,Sensor::getSensorClass,query.getSensorClassList())
                .eq(query.getGroup()!= null,Sensor::getGroup,query.getGroup())
                .like(query.getSensorDescr()!= null,Sensor::getSensorDescr,query.getSensorDescr())
                .orderByDesc(Sensor::getSensorCurrent);
        List<Sensor> list = this.list(wrapper);
        return list;
    }
}
